<?php
require_once(dirname(__FILE__)."/../lib/Loader.php");
cfgload("defines");
cload("Smarty.smartyRenderer");
cload("requestProcessor");
cload("templatesData.templateRow");

/**
 * Description of admTemplatesForm
 *
 * @author Di_Moon
 */
class admTemplatesForm extends smartyRenderer {
    protected $_dbh;
    protected $_id;
            
    function __construct($dbh) {
        parent::__construct();
        
        $this->_dbh = $dbh;
        $this->_id = (int)requestProcessor::getVar("id", 0);
    }
    
    function render() {
        $row = new templateRow($this->_dbh, $this->_id);
        $row->load();
        
        $action = requestProcessor::getVar("action");
        if($action=="send") {
            $_post = requestProcessor::post();
            $_post->del("action");
            
            $_post->get("kinopoisk", "0");
            $_post->get("itunes", "0");
            
            $row->setElements($_post);
            $row->save();
        }
        
        $formData = array();
        $formData["id"] = $this->_id;
        $formData["name"] = htmlspecialchars($row->get("name"));
        $formData["value"] = htmlspecialchars($row->get("value"));
        $formData["kinopoisk"] = $row->get("kinopoisk");
        $formData["itunes"] = $row->get("itunes");
        $formData["tpl_for"] = $row->get("tpl_for");
        
        $this->assign("formData", $formData);
        
        return $this->fetch("admTemplatesForm.tpl");
    }
}

?>
